'''
Created on Oct 20, 2011

@author: hp
'''
import os
import sys

import numpy as np
import matplotlib.pyplot as plt

def draw_verbs():
    
    N = 4
    
    precision = (0.94, 0.86, 0.97, 0.68)
    ind = np.arange(N)  # the x locations for the groups
    width = 0.15      # the width of the bars
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.bar(ind, precision, width, color='r', label="Precision")
    
    recall = (0.23, 0.09, 0.25, 0.30)
    ax.bar(ind+width, recall, width, color='y', label="Recall")
    
    f1 = (0.37, 0.16, 0.40, 0.42)
    ax.bar(ind+2*width, f1, width, color='c', label="F1")
        
    # add some
    ax.set_ylabel('Scores')
    ax.set_title('Precision/Recall/F1')
    ax.set_xticks(ind+width+0.1)
    ax.set_xticklabels( ('Abandon', 'Acknowledge', 'Acquire', 'Arrive') )
    
    plt.legend(loc=1)
    plt.show()
    
def draw_compare():
    
    N = 4
    precision = (0.94, 0.86, 0.97, 0.68)
    ind = np.arange(N)  # the x locations for the groups
    width = 0.15      # the width of the bars
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
#    ax.bar(ind, precision, width, color='r')
#    
#    recall = (0.23, 0.09, 0.25, 0.30)
#    ax.bar(ind+width, recall, width, color='y')
#    
#    precision2 = (0.89,0.87,0.93,0.92)
#    ax.bar(ind+2*width, precision2, width, color='c')
#    
#    recall2 = (0.46,0.22,0.58,0.54)
#    ax.bar(ind+3*width, recall2, width, color='g')
    
    f11 = (0.37, 0.16, 0.40, 0.42)
    f12 = (0.60, 0.36, 0.72, 0.68)
    ax.bar(ind, f11, width, color='r', label="F1-complete")
    ax.bar(ind+width, f12, width, color='y', label="F1-incomplete")
        
    # add some
    ax.set_ylabel('Scores')
    ax.set_title('F1')
    ax.set_xticks(ind+width)
    ax.set_xticklabels( ('Abandon', 'Acknowledge', 'Acquire', 'Arrive') )
    
    plt.legend(loc=2)
    plt.show()
    
def draw_compare_strategy():
    
    N = 4
    ind = np.arange(N)  # the x locations for the groups
    width = 0.15      # the width of the bars
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    
    precision = (0.89,0.93,0.92,0.87)
    precision2 = (0.97,0.97,1.0,0.90)
    precision3 = (1.0,1.0,0.81,1.0)    
    ax.bar(ind, precision, width, color='r', label="Baseline")
    ax.bar(ind+width, precision2, width, color='c', label="3Freq")
    ax.bar(ind+2*width, precision3, width, color='y', label="NOFreq")
        
#    recall = (0.46,0.58,0.54,0.22)
#    ax.bar(ind, recall, width, color='r', label="Baseline")
#    recall2 = (0.60,0.60,0.41,0.25)
#    ax.bar(ind+width, recall2, width, color='c', label="3Freq")
#    recall3 = (0.54,0.54,0.47,0.21)    
#    ax.bar(ind+2*width, recall3, width, color='y', label="NOFreq")
    
#    f11 = (0.60, 0.72, 0.68, 0.36)
#    f12 = (0.74, 0.74, 0.59, 0.39)
#    f13 = (0.70, 0.70, 0.59, 0.35)   
#    ax.bar(ind, f11, width, color='r', label="Baseline") 
#    ax.bar(ind+width, f12, width, color='y', label="3Freq")
#    ax.bar(ind+2*width, f13, width, color='c', label="NOFreq")
    # add some
    ax.set_ylabel('Scores')
    ax.set_title('Precision')
    ax.set_xticks(ind+width+0.1)
    ax.set_xticklabels( ('Abandon', 'Acquire', 'Arrive', 'Acknowledge') )
    
#    plt.legend(bbox_to_anchor=(1.05, 1), loc=1, borderaxespad=0.)    
    plt.show()

def standard_file():
    
    for fname in os.listdir('../../data/testSO'):
        if fname.find('POS') == -1:
            continue
        fpath = '../../data/testSO/' + fname
        print fpath
        fin = open(fpath, 'r')
        fout = open(fpath + '.test', 'w')
        try:
            for line in fin.read().split('\n'):
                line = line.replace('(vine din baseline)','')
                fout.write(line + '\n')
        finally:
            fin.close()
            fout.close()

if __name__ == "__main__":
    #draw_verbs()
    #draw_compare()
    #draw_compare_strategy()
    standard_file()